package org.metasketch.ham.diagrams;

import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;

import org.metasketch.diagram.javafx.graphics.BaseGraphic;
import org.metasketch.diagram.javafx.graphics.CustomLabel;
import org.metasketch.graphics.GraphicNode;

public class HumanActivityNode extends BaseGraphic {

	CustomLabel nameLabel = new CustomLabel("Untitled");
	// Rectangle rect;// = new Rectangle();

	Polygon polygon1 = new Polygon();

	Color lineColor = Color.BLACK;
	Color backColor = Color.WHITE;

	public HumanActivityNode() {
		super(new GraphicNode(0, 0, 120, 50));
		// setup(x, y, width, height);

		// setResizable(Resizableness.HORIZONTAL);
	}

	@Override
	protected void continueSetup() {

		setupGraphic(graphicNode.getX(), graphicNode.getY(),
				graphicNode.getWidth(), graphicNode.getHeight());

	}

	private void setupGraphic(int x, int y, int width, int height) {

		this.width = width;
		this.height = height;

		setX(x);
		setY(y);

		// rect = new Rectangle(1, 1, width, height);
		polygon1.setStroke(lineColor);
		polygon1.setStrokeWidth(2);
		polygon1.setFill(backColor);

		buildShape();

		// rect.setStyle("-fx-stroke: green;  -fx-stroke-width: 5;  -fx-stroke-type: outside; -fx-stroke-dash-array: 5,5; -fx-opacity: 0.5;");
		// rect.setD
		nameLabel.setGraphic(this);
		nameLabel.setFieldNameEditing("name", true);
		nameLabel.setVerticallyCentered(true);
		nameLabel.setHorizontallyCentered(true);
		nameLabel.setRightPadding("0.3%");

		// identifierLabel.setReadScript("semantic.identifier");
		// nameLabel.setReadScript("semantic.name");

		// identifierLabel.setWriteScript("semantic.identifier = text;");
		// nameLabel.setWriteScript("semantic.name = text;");

		// nameLabel.setReadScript(" if(semantic.initiates.size()==0) return semantic.name; else { return semantic.name + ' -> ' + semantic.initiates[0].getIdentifier();   }  ");
		// nameLabel.setEditable(false);

		getChildren().addAll(polygon1, nameLabel);
	}

	@Override
	protected void resizeGraphic() {
		// rect.setWidth(width);
		// rect.setHeight(height);

		// identifierLabel.resize();
		nameLabel.resize();

		buildShape();

	}

	private void buildShape() {
		polygon1.getPoints().clear();

		double startArrowWidth = width - width * 0.3d;
		polygon1.getPoints().addAll(
				new Double[] { 0d, 0d, startArrowWidth, 0d, (double) width,
						height * 0.5, startArrowWidth, (double) height, 0d,
						(double) height });
	}

	@Override
	protected void refreshModelGraphic() {
		nameLabel.refreshModelGraphic();
	}

}
